from __future__ import with_statement
import re
# import configParser #python 2.7
import configparser

class lod_cfg():
    def __init__(self):
        self.path = "./data/LLMI.ini"

    def load_cfg(self,path):
        n_cfg = configparser.ConfigParser()
        try:
            n_cfg.read(path)
        except Exception as e:
            content = open(path).read()
            content = re.sub(r"\xfe\xff", "", content)
            content = re.sub(r"\xff\xfe", "", content)
            content = re.sub(r"\xef\xbb\xbf", "", content)
            open(path, 'w').write(content)
            n_cfg.read(path)
        return n_cfg

    def lod_cfg_type(self,type):
        cfg = self.load_cfg(self.path)
        SS = cfg._sections
        try:
            return cfg._sections.get(type)
        except:
            return False
